package com.bestcem.xm.award.controller.param.draw;

import com.alibaba.fastjson.JSON;
import com.bestcem.xm.award.grpc.service.param.draw.SaveWinnerMessageParam;
import com.bestcem.xm.award.grpc.service.param.draw.WinnerParam;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.Map;

/**
 * 保存中奖信息请求参数
 *
 * @author hang.li <hang.li@idiaoyan.com>
 * @version v1.0
 * @date 2021/8/20 10:34
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SaveWinnerMessageRequestParam {

    /**
     * 奖励信息
     */
    @NotNull(message = "奖励信息缺失")
    private Map<String, Object> award;

    /**
     * 中奖人信息
     */
    @Valid
    @NotNull(message = "中奖人信息不能为空")
    @JsonProperty("winner")
    private WinnerParam winnerParam;

    /**
     * 保存中奖信息参数转换
     * @return {@link SaveWinnerMessageParam}
     */
    public SaveWinnerMessageParam getSaveWinnerMessageParam() {
        SaveWinnerMessageParam param = JSON.parseObject(JSON.toJSONString(this.award), SaveWinnerMessageParam.class);
        param.setWinnerParam(this.winnerParam);
        return param;
    }
}
